from fastapi import APIRouter
from pydantic import BaseModel
from intelli_port.model import PaddleASRInferencer, PaddleTTSInferencer, PaddleOCRInferencer


router = APIRouter()
asr = PaddleASRInferencer()
tts = PaddleTTSInferencer()
ocr = PaddleOCRInferencer()


class ASRRequest(BaseModel):
    path: str
    lang: str | None = None


class TTSRequest(BaseModel):
    text: str
    out_path: str
    lang: str | None = None
    voice: str | None = None


class OCRRequest(BaseModel):
    path: str
    lang: str | None = None


@router.post("/asr/transcribe")
async def asr_transcribe(req: ASRRequest):
    return asr.transcribe_wav(req.path, lang=req.lang)


@router.post("/tts/synthesize")
async def tts_synthesize(req: TTSRequest):
    return tts.synthesize_to_wav(req.text, req.out_path, lang=req.lang, voice=req.voice)


@router.post("/ocr/scan")
async def ocr_scan(req: OCRRequest):
    return ocr.scan_image(req.path, lang=req.lang)